import sys
import random

def getConfig(host = '224.1.1.1', port = 10001, \
              min = 2000, max = 3000, count = 1000, \
              symbol = 'ZYZZT', user = 9999):
    configData = {}
    configData['host']  = host
    configData['port']  = port
    configData['min']   = min
    configData['max']   = max
    configData['count'] = count
    configData['symbol']= symbol
    configData['user']  = user
    
    return configData

def getMEConfig(host = '224.1.1.2', port = 10002):
    configData = {}
    configData['host']  = host
    configData['port']  = port
    
    return configData


def getQSConfig(host = '224.1.1.3', port = 10003, \
                min = 2000, max = 3000, count = 1000, \
                symbol = 'ZYZZT', user = 9999):
    configData = {}
    configData['host']  = host
    configData['port']  = port
    configData['min']   = min
    configData['max']   = max
    configData['count'] = count
    configData['symbol']= symbol
    configData['user']  = user
    
    return configData


def getOSConfig(host = '224.1.1.4', port = 10004, \
                min = 2000, max = 3000, count = 1000, \
                symbol = 'ZYZZT', user = 9999):
    configData = {}
    configData['host']  = host
    configData['port']  = port
    configData['min']   = min
    configData['max']   = max
    configData['count'] = count
    configData['symbol']= symbol
    configData['user']  = user
    
    return configData
    

def getSSConfig(host = '224.1.1.5', port = 10005, \
                min = 1000, max = 3000, count = 1000, \
                symbol = 'ZYZZT', user = 9999):
    configData = {}
    configData['host']  = host
    configData['port']  = port
    configData['min']   = min
    configData['max']   = max
    configData['count'] = count
    configData['symbol']= symbol
    configData['user']  = user
    
    return configData


def getGWConfig(host = '172.0.0.1', port = 20001):
    configData = {}
    configData['host']  = host
    configData['port']  = port
    
    return configData


def makeOrders(userId = "9999", min = 15000, max = 30000,\
                count = 100, symbol = 'ZYZZT'):
    orders = []
    while count != 0:
        count -= 1
        price = float(random.randint(min,max)) / 100
        side = random.randint(0,1)
        size = random.randrange(100, 1500, 100)
        order = (userId, symbol, side, size, price)
        orders.append(order)
        
    return orders

def makeQuotes(min = 2000, max = 3000, count = 100, symbol = 'ZYZZT'):
    quotes = []
    while count != 0:
        count -= 1
        price = float(random.randint(min,max)) / 100
        side = random.randint(0,1)
        size = random.randrange(100, 500, 100)
        quote = (symbol, side, size, price)
        quotes.append(quote)
        
    return quotes


class orderObject():
    def __init__(self, symbol, user, orderNumber, side,  price, size, time):
        self.symbol = symbol
        self.user = user
        self.orderNum = orderNumber
        self.side = side
        self.price = price
        self.size = size
        self.time = time
    def __repr__(self):
        return repr((self.symbol, self.user, self.orderNum, self.price, self.size, self.time))
 

class quoteObject():
    def __init__(self, symbol = 'ZYZZT', price = 0.0, size = 0):
        self.symbol = symbol
        self.price = price
        self.size = size
        
    def __repr__(self):
        return repr((self.symbol, self.price, self.size))
        
    
def initFullBook():
    book = dict (bid1 = 0.0, bSize1 = 0,    ask1=0.0, aSize1 = 0, \
                 bid2 = 0.0, bSize2 = 0,    ask2=0.0, aSize2 = 0, \
                 bid3 = 0.0, bSize3 = 0,    ask3=0.0, aSize3 = 0, \
                 bid4 = 0.0, bSize4 = 0,    ask4=0.0, aSize4 = 0, \
                 bid5 = 0.0, bSize5 = 0,    ask5=0.0, aSize5 = 0  )
    return book

def initTestBook():
    book = dict (bid1 = 25.0, bSize1 = 1000,    ask1=26.0, aSize1 = 1000, \
                 bid2 = 24.0, bSize2 = 1000,    ask2=27.0, aSize2 = 1000, \
                 bid3 = 23.0, bSize3 = 1000,    ask3=28.0, aSize3 = 1000, \
                 bid4 = 22.0, bSize4 = 1000,    ask4=29.0, aSize4 = 1000, \
                 bid5 = 21.0, bSize5 = 1000,    ask5=30.0, aSize5 = 1000  )
    return book

def bookDictToList(bookDict):
    
    bookList = (bookDict['bid1'], bookDict['bSize1'], bookDict['ask1'], bookDict['aSize1'], \
                bookDict['bid2'], bookDict['bSize2'], bookDict['ask2'], bookDict['aSize2'], \
                bookDict['bid3'], bookDict['bSize3'], bookDict['ask3'], bookDict['aSize3'], \
                bookDict['bid4'], bookDict['bSize4'], bookDict['ask4'], bookDict['aSize4'], \
                bookDict['bid5'], bookDict['bSize5'], bookDict['ask5'], bookDict['aSize5'])
    return bookList

def bookListToDict(bookList):
    if len(bookList) != 20:
        return "Error converting BookList to Dict.  Not 20 elements"
    
    bookDict = dict(bid1 = bookList[0], bSize1 = bookList[1], ask1 = bookList[2], aSize1 = bookList[3],     \
               bid2 = bookList[4], bSize2 = bookList[5], ask2 = bookList[6], aSize2 = bookList[7],          \
               bid3 = bookList[8], bSize3 = bookList[9], ask3 = bookList[10], aSize3 = bookList[11],        \
               bid4 = bookList[12], bSize4 = bookList[13], ask4 = bookList[14], aSize4 = bookList[15],      \
               bid5 = bookList[16], bSize5 = bookList[17], ask5 = bookList[18], aSize5 = bookList[19])
    return bookDict

def printBook(bookList):
    out = """bid1 =  %s bSize1 =  %s ask1 =  %s aSize1 =  %s \n
bid2 =  %s bSize2 =  %s ask2 =  %s aSize2 =  %s \n
bid3 =  %s bSize3 =  %s ask3 =  %s aSize3 =  %s \n
bid4 =  %s bSize4 =  %s ask4 =  %s aSize4 =  %s \n
bid5 =  %s bSize5 =  %s ask5 =  %s aSize5 =  %s \n\n"""  % bookList
    print out
    
    
def initFakeBook():
    book = (25.0, 1000, 26.0, 1000, \
            24.0, 1000, 27.0, 1000, \
            23.0, 1000, 28.0, 1000, \
            22.0, 1000, 29.0, 1000, \
            21.0, 1000, 30.0, 1000  )
    return book
                 